﻿//#define DEBUG_SHOW_CREATION

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Drawing;
using System.Windows.Forms; //for Color class

namespace DirectX_CS
{

    public class FluidOld : Form, IManagedModelView, IManagedVertexBuffer, IManagedIndexBuffer, IManagedMaterial, IColorable, IAnimated
    {
		const float PI = (float)Math.PI;

		protected double mTime = 0;
		protected Device mDevice = null;
		protected bool mRegistered = false;
		protected ManagedRenderer renderer = null; //main memory manager..change name.

		public event VBChangedDelegate VertexBufferChanged;
		public event IBChangedDelegate IndexBufferChanged;

		protected Material mMaterial;
		protected Color mMaterialColor = Color.Black;
		protected Color mVertexColor = Color.MidnightBlue;

		protected int renderCounts = 0;
		private int framesPerRender = 10;

		protected int FramesPerRender
		{
			get { return framesPerRender; }
			set { if (value > 1)
				framesPerRender = value; }
		}

		protected Vector3 position;
		private float yaw = 1;	 //should be zero .. changed for test

		[PGBrowsableAttribute]
		public float Yaw
		{
			get { return yaw; }
			set { yaw = value; }
		}
		private float pitch = 10;

		[PGBrowsableAttribute]
		public float Pitch
		{
			get { return pitch; }
			set { pitch = value; }
		}
		private float roll = 1;

		[PGBrowsableAttribute]
		public float Roll
		{
			get { return roll; }
			set { roll = value; }
		}

		//public delegate double PolarRT_ZFunc(double radius, double theta);

		//protected Array mIndexData = null;
		protected int[] mSurfaceIndices = null;
        protected Array mVertexData = null;


		protected bool initializing = false;

//        #region "Designer Generated - Definitions"

//        private SplitContainer splitContainer1;
//        private PropertyGrid pgSelfViewer;
//        private NumericUpDown nudGlobalTime;
//        private Button btnEnableAllTimers;
//        private SplitContainer scWaves;
//        private Label lblDesc_Waves;
//        private PropertyGrid pgSelectedWaves;
//        private ListBox lbLateralWaves;
//        private Button btnRemoveSelectedWaves;
//        private Label label18;
//        private Label label17;
//        private Label lblDescAdd;
//        private TabControl tabControl1;
//        private TabPage tpGeneral;
//        private RadioButton rbWaveTypeSquare;
//        private RadioButton rbWaveTypeCos;
//        private RadioButton rbWaveTypeSin;
//        private RadioButton rbWaveTypeWater;
//        private CheckBox chkSetOutOfBoundsToZero;
//        private RadioButton rbWaveTypeNormalCurve;
//        private RadioButton rbWaveTypeSawTooth;
//        private CheckBox chkChangeCamera;
//        private CheckBox chkLocalTimerEnabled;
//        private Label label12;
//        private Label label13;
//        private NumericUpDown nudLifeTimeMax;
//        private Label label2;
//        private NumericUpDown nudLifeTimeMin;
//        private Label label14;
//        private Label label16;
//        private NumericUpDown nudAmplitudeMax;
//        private Label lblDesc_Amplitude;
//        private NumericUpDown nudAmplitudeMin;
//        private Label label19;
//        private Label label20;
//        private Label label21;
//        private Label label11;
//        private Label label10;
//        private Label label9;
//        private NumericUpDown nudXMax;
//        private NumericUpDown nudYMax;
//        private NumericUpDown nudZMax;
//        private NumericUpDown nudXMin;
//        private NumericUpDown nudYMin;
//        private NumericUpDown nudZMin;
//        private Label label5;
//        private Label label4;
//        private Label lblDesc_CenterPosition;
//        private TabPage tpSinAndCos;
//        private Label label23;
//        private Label label22;
//        private NumericUpDown nudFrequencyMax;
//        private NumericUpDown nudFrequencyMin;
//        private Label label7;
//        private Label label15;
//        private NumericUpDown nudFixedWaveCount;
//        private TabPage tpNormal;
//        private Label label24;
//        private NumericUpDown nudNormalVarianceMin;
//        private Label label8;
//        private NumericUpDown nudRadialSpeedMin;
//        private NumericUpDown nudR0Min;
//        private NumericUpDown nudLengthOfEffectMin;
//        private Label lblDescLengthOfEffect;
//        private Label label1;
//        private CheckBox chkGlobalTimerEnabled;
//        private NumericUpDown nudNormalVarianceMax;
//        private NumericUpDown nudRadialSpeedMax;
//        private NumericUpDown nudR0Max;
//        private NumericUpDown nudLengthOfEffectMax;
//        private Label label6;
//        private Label label25;
//        private Button btnAddWaves;
//        private NumericUpDown nudCount;
//        private Label label3;
//        private Button btnDisableAllTimers;
		

//#endregion	 

//        #region "Designer Generated - InitializeComponent"

//        private void InitializeComponent()
//        {
//            this.splitContainer1 = new System.Windows.Forms.SplitContainer();
//            this.chkGlobalTimerEnabled = new System.Windows.Forms.CheckBox();
//            this.btnDisableAllTimers = new System.Windows.Forms.Button();
//            this.btnEnableAllTimers = new System.Windows.Forms.Button();
//            this.nudGlobalTime = new System.Windows.Forms.NumericUpDown();
//            this.pgSelfViewer = new System.Windows.Forms.PropertyGrid();
//            this.scWaves = new System.Windows.Forms.SplitContainer();
//            this.label18 = new System.Windows.Forms.Label();
//            this.label17 = new System.Windows.Forms.Label();
//            this.btnRemoveSelectedWaves = new System.Windows.Forms.Button();
//            this.lblDesc_Waves = new System.Windows.Forms.Label();
//            this.pgSelectedWaves = new System.Windows.Forms.PropertyGrid();
//            this.lbLateralWaves = new System.Windows.Forms.ListBox();
//            this.btnAddWaves = new System.Windows.Forms.Button();
//            this.nudCount = new System.Windows.Forms.NumericUpDown();
//            this.label3 = new System.Windows.Forms.Label();
//            this.lblDescAdd = new System.Windows.Forms.Label();
//            this.tabControl1 = new System.Windows.Forms.TabControl();
//            this.tpGeneral = new System.Windows.Forms.TabPage();
//            this.rbWaveTypeSquare = new System.Windows.Forms.RadioButton();
//            this.rbWaveTypeCos = new System.Windows.Forms.RadioButton();
//            this.rbWaveTypeSin = new System.Windows.Forms.RadioButton();
//            this.rbWaveTypeWater = new System.Windows.Forms.RadioButton();
//            this.chkSetOutOfBoundsToZero = new System.Windows.Forms.CheckBox();
//            this.rbWaveTypeNormalCurve = new System.Windows.Forms.RadioButton();
//            this.rbWaveTypeSawTooth = new System.Windows.Forms.RadioButton();
//            this.chkChangeCamera = new System.Windows.Forms.CheckBox();
//            this.chkLocalTimerEnabled = new System.Windows.Forms.CheckBox();
//            this.label12 = new System.Windows.Forms.Label();
//            this.label13 = new System.Windows.Forms.Label();
//            this.nudLifeTimeMax = new System.Windows.Forms.NumericUpDown();
//            this.label2 = new System.Windows.Forms.Label();
//            this.nudLifeTimeMin = new System.Windows.Forms.NumericUpDown();
//            this.label14 = new System.Windows.Forms.Label();
//            this.label16 = new System.Windows.Forms.Label();
//            this.nudAmplitudeMax = new System.Windows.Forms.NumericUpDown();
//            this.lblDesc_Amplitude = new System.Windows.Forms.Label();
//            this.nudAmplitudeMin = new System.Windows.Forms.NumericUpDown();
//            this.label19 = new System.Windows.Forms.Label();
//            this.label20 = new System.Windows.Forms.Label();
//            this.label21 = new System.Windows.Forms.Label();
//            this.label11 = new System.Windows.Forms.Label();
//            this.label10 = new System.Windows.Forms.Label();
//            this.label9 = new System.Windows.Forms.Label();
//            this.nudXMax = new System.Windows.Forms.NumericUpDown();
//            this.nudYMax = new System.Windows.Forms.NumericUpDown();
//            this.nudZMax = new System.Windows.Forms.NumericUpDown();
//            this.nudXMin = new System.Windows.Forms.NumericUpDown();
//            this.nudYMin = new System.Windows.Forms.NumericUpDown();
//            this.nudZMin = new System.Windows.Forms.NumericUpDown();
//            this.label5 = new System.Windows.Forms.Label();
//            this.label4 = new System.Windows.Forms.Label();
//            this.lblDesc_CenterPosition = new System.Windows.Forms.Label();
//            this.tpSinAndCos = new System.Windows.Forms.TabPage();
//            this.label23 = new System.Windows.Forms.Label();
//            this.label22 = new System.Windows.Forms.Label();
//            this.nudFrequencyMax = new System.Windows.Forms.NumericUpDown();
//            this.nudFrequencyMin = new System.Windows.Forms.NumericUpDown();
//            this.label7 = new System.Windows.Forms.Label();
//            this.label15 = new System.Windows.Forms.Label();
//            this.nudFixedWaveCount = new System.Windows.Forms.NumericUpDown();
//            this.tpNormal = new System.Windows.Forms.TabPage();
//            this.label6 = new System.Windows.Forms.Label();
//            this.label25 = new System.Windows.Forms.Label();
//            this.nudNormalVarianceMax = new System.Windows.Forms.NumericUpDown();
//            this.nudRadialSpeedMax = new System.Windows.Forms.NumericUpDown();
//            this.nudR0Max = new System.Windows.Forms.NumericUpDown();
//            this.nudLengthOfEffectMax = new System.Windows.Forms.NumericUpDown();
//            this.label24 = new System.Windows.Forms.Label();
//            this.nudNormalVarianceMin = new System.Windows.Forms.NumericUpDown();
//            this.label8 = new System.Windows.Forms.Label();
//            this.nudRadialSpeedMin = new System.Windows.Forms.NumericUpDown();
//            this.nudR0Min = new System.Windows.Forms.NumericUpDown();
//            this.nudLengthOfEffectMin = new System.Windows.Forms.NumericUpDown();
//            this.lblDescLengthOfEffect = new System.Windows.Forms.Label();
//            this.label1 = new System.Windows.Forms.Label();
//            this.splitContainer1.Panel1.SuspendLayout();
//            this.splitContainer1.Panel2.SuspendLayout();
//            this.splitContainer1.SuspendLayout();
//            ((System.ComponentModel.ISupportInitialize)(this.nudGlobalTime)).BeginInit();
//            this.scWaves.Panel1.SuspendLayout();
//            this.scWaves.Panel2.SuspendLayout();
//            this.scWaves.SuspendLayout();
//            ((System.ComponentModel.ISupportInitialize)(this.nudCount)).BeginInit();
//            this.tabControl1.SuspendLayout();
//            this.tpGeneral.SuspendLayout();
//            ((System.ComponentModel.ISupportInitialize)(this.nudLifeTimeMax)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudLifeTimeMin)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudAmplitudeMax)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudAmplitudeMin)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudXMax)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudYMax)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudZMax)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudXMin)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudYMin)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudZMin)).BeginInit();
//            this.tpSinAndCos.SuspendLayout();
//            ((System.ComponentModel.ISupportInitialize)(this.nudFrequencyMax)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudFrequencyMin)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudFixedWaveCount)).BeginInit();
//            this.tpNormal.SuspendLayout();
//            ((System.ComponentModel.ISupportInitialize)(this.nudNormalVarianceMax)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudRadialSpeedMax)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudR0Max)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudLengthOfEffectMax)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudNormalVarianceMin)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudRadialSpeedMin)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudR0Min)).BeginInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudLengthOfEffectMin)).BeginInit();
//            this.SuspendLayout();
//            // 
//            // splitContainer1
//            // 
//            this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
//            this.splitContainer1.Location = new System.Drawing.Point(0, 0);
//            this.splitContainer1.Name = "splitContainer1";
//            // 
//            // splitContainer1.Panel1
//            // 
//            this.splitContainer1.Panel1.Controls.Add(this.chkGlobalTimerEnabled);
//            this.splitContainer1.Panel1.Controls.Add(this.btnDisableAllTimers);
//            this.splitContainer1.Panel1.Controls.Add(this.btnEnableAllTimers);
//            this.splitContainer1.Panel1.Controls.Add(this.nudGlobalTime);
//            this.splitContainer1.Panel1.Controls.Add(this.pgSelfViewer);
//            // 
//            // splitContainer1.Panel2
//            // 
//            this.splitContainer1.Panel2.Controls.Add(this.scWaves);
//            this.splitContainer1.Size = new System.Drawing.Size(596, 570);
//            this.splitContainer1.SplitterDistance = 195;
//            this.splitContainer1.TabIndex = 0;
//            // 
//            // chkGlobalTimerEnabled
//            // 
//            this.chkGlobalTimerEnabled.AutoSize = true;
//            this.chkGlobalTimerEnabled.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
//            this.chkGlobalTimerEnabled.Location = new System.Drawing.Point(12, 32);
//            this.chkGlobalTimerEnabled.Name = "chkGlobalTimerEnabled";
//            this.chkGlobalTimerEnabled.Size = new System.Drawing.Size(155, 17);
//            this.chkGlobalTimerEnabled.TabIndex = 7;
//            this.chkGlobalTimerEnabled.Text = "(Global) Timer &Enabled";
//            this.chkGlobalTimerEnabled.UseVisualStyleBackColor = true;
//            // 
//            // btnDisableAllTimers
//            // 
//            this.btnDisableAllTimers.Location = new System.Drawing.Point(3, 87);
//            this.btnDisableAllTimers.Name = "btnDisableAllTimers";
//            this.btnDisableAllTimers.Size = new System.Drawing.Size(117, 23);
//            this.btnDisableAllTimers.TabIndex = 6;
//            this.btnDisableAllTimers.Text = "&Disable All Timers";
//            this.btnDisableAllTimers.UseVisualStyleBackColor = true;
//            this.btnDisableAllTimers.Click += new System.EventHandler(this.btnDisableAllTimers_Click);
//            // 
//            // btnEnableAllTimers
//            // 
//            this.btnEnableAllTimers.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
//            this.btnEnableAllTimers.Location = new System.Drawing.Point(0, 58);
//            this.btnEnableAllTimers.Name = "btnEnableAllTimers";
//            this.btnEnableAllTimers.Size = new System.Drawing.Size(117, 23);
//            this.btnEnableAllTimers.TabIndex = 5;
//            this.btnEnableAllTimers.Text = "&Enable All Timers";
//            this.btnEnableAllTimers.UseVisualStyleBackColor = true;
//            this.btnEnableAllTimers.Click += new System.EventHandler(this.btnEnableAllTimers_Click);
//            // 
//            // nudGlobalTime
//            // 
//            this.nudGlobalTime.DecimalPlaces = 3;
//            this.nudGlobalTime.Location = new System.Drawing.Point(12, 7);
//            this.nudGlobalTime.Maximum = new decimal(new int[] {
//            1316134912,
//            2328,
//            0,
//            0});
//            this.nudGlobalTime.Minimum = new decimal(new int[] {
//            1316134912,
//            2328,
//            0,
//            -2147483648});
//            this.nudGlobalTime.Name = "nudGlobalTime";
//            this.nudGlobalTime.Size = new System.Drawing.Size(81, 20);
//            this.nudGlobalTime.TabIndex = 4;
//            this.nudGlobalTime.ValueChanged += new System.EventHandler(this.nudGlobalTime_ValueChanged);
//            // 
//            // pgSelfViewer
//            // 
//            this.pgSelfViewer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
//                        | System.Windows.Forms.AnchorStyles.Left)
//                        | System.Windows.Forms.AnchorStyles.Right)));
//            this.pgSelfViewer.HelpVisible = false;
//            this.pgSelfViewer.ImeMode = System.Windows.Forms.ImeMode.Off;
//            this.pgSelfViewer.Location = new System.Drawing.Point(3, 123);
//            this.pgSelfViewer.Name = "pgSelfViewer";
//            this.pgSelfViewer.Size = new System.Drawing.Size(189, 445);
//            this.pgSelfViewer.TabIndex = 2;
//            this.pgSelfViewer.ToolbarVisible = false;
//            this.pgSelfViewer.PropertyValueChanged += new System.Windows.Forms.PropertyValueChangedEventHandler(this.pgSelfViewer_PropertyValueChanged);
//            // 
//            // scWaves
//            // 
//            this.scWaves.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
//            this.scWaves.Dock = System.Windows.Forms.DockStyle.Fill;
//            this.scWaves.Location = new System.Drawing.Point(0, 0);
//            this.scWaves.Name = "scWaves";
//            this.scWaves.Orientation = System.Windows.Forms.Orientation.Horizontal;
//            // 
//            // scWaves.Panel1
//            // 
//            this.scWaves.Panel1.Controls.Add(this.label18);
//            this.scWaves.Panel1.Controls.Add(this.label17);
//            this.scWaves.Panel1.Controls.Add(this.btnRemoveSelectedWaves);
//            this.scWaves.Panel1.Controls.Add(this.lblDesc_Waves);
//            this.scWaves.Panel1.Controls.Add(this.pgSelectedWaves);
//            this.scWaves.Panel1.Controls.Add(this.lbLateralWaves);
//            // 
//            // scWaves.Panel2
//            // 
//            this.scWaves.Panel2.Controls.Add(this.btnAddWaves);
//            this.scWaves.Panel2.Controls.Add(this.nudCount);
//            this.scWaves.Panel2.Controls.Add(this.label3);
//            this.scWaves.Panel2.Controls.Add(this.lblDescAdd);
//            this.scWaves.Panel2.Controls.Add(this.tabControl1);
//            this.scWaves.Size = new System.Drawing.Size(397, 570);
//            this.scWaves.SplitterDistance = 273;
//            this.scWaves.SplitterIncrement = 3;
//            this.scWaves.TabIndex = 39;
//            // 
//            // label18
//            // 
//            this.label18.AutoSize = true;
//            this.label18.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
//            this.label18.Location = new System.Drawing.Point(6, 7);
//            this.label18.Name = "label18";
//            this.label18.Size = new System.Drawing.Size(91, 13);
//            this.label18.TabIndex = 42;
//            this.label18.Text = "Current Waves";
//            // 
//            // label17
//            // 
//            this.label17.AutoSize = true;
//            this.label17.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
//            this.label17.Location = new System.Drawing.Point(175, 7);
//            this.label17.Name = "label17";
//            this.label17.Size = new System.Drawing.Size(177, 13);
//            this.label17.TabIndex = 41;
//            this.label17.Text = "Settings for Selected Wave(s)";
//            // 
//            // btnRemoveSelectedWaves
//            // 
//            this.btnRemoveSelectedWaves.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
//            this.btnRemoveSelectedWaves.Location = new System.Drawing.Point(9, 233);
//            this.btnRemoveSelectedWaves.Name = "btnRemoveSelectedWaves";
//            this.btnRemoveSelectedWaves.Size = new System.Drawing.Size(158, 23);
//            this.btnRemoveSelectedWaves.TabIndex = 38;
//            this.btnRemoveSelectedWaves.Text = "Remove Selected Wave(s)";
//            this.btnRemoveSelectedWaves.UseVisualStyleBackColor = true;
//            this.btnRemoveSelectedWaves.Click += new System.EventHandler(this.btnRemoveSelectedWaves_Click);
//            // 
//            // lblDesc_Waves
//            // 
//            this.lblDesc_Waves.AutoSize = true;
//            this.lblDesc_Waves.Location = new System.Drawing.Point(-21, -27);
//            this.lblDesc_Waves.Name = "lblDesc_Waves";
//            this.lblDesc_Waves.Size = new System.Drawing.Size(44, 13);
//            this.lblDesc_Waves.TabIndex = 5;
//            this.lblDesc_Waves.Text = "Waves:";
//            // 
//            // pgSelectedWaves
//            // 
//            this.pgSelectedWaves.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
//                        | System.Windows.Forms.AnchorStyles.Left)
//                        | System.Windows.Forms.AnchorStyles.Right)));
//            this.pgSelectedWaves.HelpVisible = false;
//            this.pgSelectedWaves.ImeMode = System.Windows.Forms.ImeMode.Off;
//            this.pgSelectedWaves.Location = new System.Drawing.Point(173, 26);
//            this.pgSelectedWaves.Name = "pgSelectedWaves";
//            this.pgSelectedWaves.Size = new System.Drawing.Size(220, 230);
//            this.pgSelectedWaves.TabIndex = 4;
//            this.pgSelectedWaves.ToolbarVisible = false;
//            this.pgSelectedWaves.PropertyValueChanged += new System.Windows.Forms.PropertyValueChangedEventHandler(this.pgSelectedWaves_PropertyValueChanged);
//            // 
//            // lbLateralWaves
//            // 
//            this.lbLateralWaves.FormattingEnabled = true;
//            this.lbLateralWaves.Location = new System.Drawing.Point(6, 28);
//            this.lbLateralWaves.Name = "lbLateralWaves";
//            this.lbLateralWaves.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
//            this.lbLateralWaves.Size = new System.Drawing.Size(161, 199);
//            this.lbLateralWaves.TabIndex = 3;
//            this.lbLateralWaves.SelectedIndexChanged += new System.EventHandler(this.lbLateralWaves_SelectedIndexChanged);
//            // 
//            // btnAddWaves
//            // 
//            this.btnAddWaves.Location = new System.Drawing.Point(229, -1);
//            this.btnAddWaves.Name = "btnAddWaves";
//            this.btnAddWaves.Size = new System.Drawing.Size(102, 20);
//            this.btnAddWaves.TabIndex = 137;
//            this.btnAddWaves.Text = "&Add New Wave";
//            this.btnAddWaves.UseVisualStyleBackColor = true;
//            this.btnAddWaves.Click += new System.EventHandler(this.btnAddWave_RandomNew_Click);
//            // 
//            // nudCount
//            // 
//            this.nudCount.Location = new System.Drawing.Point(172, 1);
//            this.nudCount.Name = "nudCount";
//            this.nudCount.Size = new System.Drawing.Size(51, 20);
//            this.nudCount.TabIndex = 139;
//            this.nudCount.Value = new decimal(new int[] {
//            1,
//            0,
//            0,
//            0});
//            // 
//            // label3
//            // 
//            this.label3.BackColor = System.Drawing.SystemColors.Control;
//            this.label3.Location = new System.Drawing.Point(6, 3);
//            this.label3.Name = "label3";
//            this.label3.Size = new System.Drawing.Size(175, 18);
//            this.label3.TabIndex = 138;
//            this.label3.Text = "Number of random waves to add:";
//            // 
//            // lblDescAdd
//            // 
//            this.lblDescAdd.BackColor = System.Drawing.SystemColors.Control;
//            this.lblDescAdd.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
//            this.lblDescAdd.Location = new System.Drawing.Point(6, 28);
//            this.lblDescAdd.Name = "lblDescAdd";
//            this.lblDescAdd.Size = new System.Drawing.Size(191, 13);
//            this.lblDescAdd.TabIndex = 136;
//            this.lblDescAdd.Text = "Settings for Adding New Waves:";
//            // 
//            // tabControl1
//            // 
//            this.tabControl1.Controls.Add(this.tpGeneral);
//            this.tabControl1.Controls.Add(this.tpSinAndCos);
//            this.tabControl1.Controls.Add(this.tpNormal);
//            this.tabControl1.HotTrack = true;
//            this.tabControl1.Location = new System.Drawing.Point(3, 44);
//            this.tabControl1.Multiline = true;
//            this.tabControl1.Name = "tabControl1";
//            this.tabControl1.SelectedIndex = 0;
//            this.tabControl1.Size = new System.Drawing.Size(387, 242);
//            this.tabControl1.TabIndex = 133;
//            // 
//            // tpGeneral
//            // 
//            this.tpGeneral.Controls.Add(this.rbWaveTypeSquare);
//            this.tpGeneral.Controls.Add(this.rbWaveTypeCos);
//            this.tpGeneral.Controls.Add(this.rbWaveTypeSin);
//            this.tpGeneral.Controls.Add(this.rbWaveTypeWater);
//            this.tpGeneral.Controls.Add(this.chkSetOutOfBoundsToZero);
//            this.tpGeneral.Controls.Add(this.rbWaveTypeNormalCurve);
//            this.tpGeneral.Controls.Add(this.rbWaveTypeSawTooth);
//            this.tpGeneral.Controls.Add(this.chkChangeCamera);
//            this.tpGeneral.Controls.Add(this.chkLocalTimerEnabled);
//            this.tpGeneral.Controls.Add(this.label12);
//            this.tpGeneral.Controls.Add(this.label13);
//            this.tpGeneral.Controls.Add(this.nudLifeTimeMax);
//            this.tpGeneral.Controls.Add(this.label2);
//            this.tpGeneral.Controls.Add(this.nudLifeTimeMin);
//            this.tpGeneral.Controls.Add(this.label14);
//            this.tpGeneral.Controls.Add(this.label16);
//            this.tpGeneral.Controls.Add(this.nudAmplitudeMax);
//            this.tpGeneral.Controls.Add(this.lblDesc_Amplitude);
//            this.tpGeneral.Controls.Add(this.nudAmplitudeMin);
//            this.tpGeneral.Controls.Add(this.label19);
//            this.tpGeneral.Controls.Add(this.label20);
//            this.tpGeneral.Controls.Add(this.label21);
//            this.tpGeneral.Controls.Add(this.label11);
//            this.tpGeneral.Controls.Add(this.label10);
//            this.tpGeneral.Controls.Add(this.label9);
//            this.tpGeneral.Controls.Add(this.nudXMax);
//            this.tpGeneral.Controls.Add(this.nudYMax);
//            this.tpGeneral.Controls.Add(this.nudZMax);
//            this.tpGeneral.Controls.Add(this.nudXMin);
//            this.tpGeneral.Controls.Add(this.nudYMin);
//            this.tpGeneral.Controls.Add(this.nudZMin);
//            this.tpGeneral.Controls.Add(this.label5);
//            this.tpGeneral.Controls.Add(this.label4);
//            this.tpGeneral.Controls.Add(this.lblDesc_CenterPosition);
//            this.tpGeneral.Location = new System.Drawing.Point(4, 22);
//            this.tpGeneral.Name = "tpGeneral";
//            this.tpGeneral.Padding = new System.Windows.Forms.Padding(3);
//            this.tpGeneral.Size = new System.Drawing.Size(379, 216);
//            this.tpGeneral.TabIndex = 0;
//            this.tpGeneral.Text = "General Properties";
//            this.tpGeneral.UseVisualStyleBackColor = true;
//            // 
//            // rbWaveTypeSquare
//            // 
//            this.rbWaveTypeSquare.BackColor = System.Drawing.SystemColors.Control;
//            this.rbWaveTypeSquare.Location = new System.Drawing.Point(277, 123);
//            this.rbWaveTypeSquare.Name = "rbWaveTypeSquare";
//            this.rbWaveTypeSquare.Size = new System.Drawing.Size(59, 17);
//            this.rbWaveTypeSquare.TabIndex = 141;
//            this.rbWaveTypeSquare.Text = "Square";
//            this.rbWaveTypeSquare.UseVisualStyleBackColor = false;
//            this.rbWaveTypeSquare.Click += new System.EventHandler(this.rbWaveTypeSquare_Click);
//            // 
//            // rbWaveTypeCos
//            // 
//            this.rbWaveTypeCos.BackColor = System.Drawing.SystemColors.Control;
//            this.rbWaveTypeCos.Location = new System.Drawing.Point(277, 169);
//            this.rbWaveTypeCos.Name = "rbWaveTypeCos";
//            this.rbWaveTypeCos.Size = new System.Drawing.Size(43, 17);
//            this.rbWaveTypeCos.TabIndex = 140;
//            this.rbWaveTypeCos.Text = "Cos";
//            this.rbWaveTypeCos.UseVisualStyleBackColor = false;
//            this.rbWaveTypeCos.Click += new System.EventHandler(this.rbWaveTypeCos_Click);
//            // 
//            // rbWaveTypeSin
//            // 
//            this.rbWaveTypeSin.BackColor = System.Drawing.SystemColors.Control;
//            this.rbWaveTypeSin.Location = new System.Drawing.Point(277, 146);
//            this.rbWaveTypeSin.Name = "rbWaveTypeSin";
//            this.rbWaveTypeSin.Size = new System.Drawing.Size(40, 17);
//            this.rbWaveTypeSin.TabIndex = 139;
//            this.rbWaveTypeSin.Text = "Sin";
//            this.rbWaveTypeSin.UseVisualStyleBackColor = false;
//            this.rbWaveTypeSin.Click += new System.EventHandler(this.rbWaveTypeSin_Click);
//            // 
//            // rbWaveTypeWater
//            // 
//            this.rbWaveTypeWater.BackColor = System.Drawing.SystemColors.Control;
//            this.rbWaveTypeWater.Checked = true;
//            this.rbWaveTypeWater.Location = new System.Drawing.Point(277, 100);
//            this.rbWaveTypeWater.Name = "rbWaveTypeWater";
//            this.rbWaveTypeWater.Size = new System.Drawing.Size(54, 17);
//            this.rbWaveTypeWater.TabIndex = 138;
//            this.rbWaveTypeWater.TabStop = true;
//            this.rbWaveTypeWater.Text = "Water";
//            this.rbWaveTypeWater.UseVisualStyleBackColor = false;
//            this.rbWaveTypeWater.Click += new System.EventHandler(this.rbWaveTypeWater_Click);
//            // 
//            // chkSetOutOfBoundsToZero
//            // 
//            this.chkSetOutOfBoundsToZero.BackColor = System.Drawing.SystemColors.Control;
//            this.chkSetOutOfBoundsToZero.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
//            this.chkSetOutOfBoundsToZero.Location = new System.Drawing.Point(211, 193);
//            this.chkSetOutOfBoundsToZero.Name = "chkSetOutOfBoundsToZero";
//            this.chkSetOutOfBoundsToZero.Size = new System.Drawing.Size(150, 17);
//            this.chkSetOutOfBoundsToZero.TabIndex = 137;
//            this.chkSetOutOfBoundsToZero.Text = "Set Out of Bounds to Zero";
//            this.chkSetOutOfBoundsToZero.UseVisualStyleBackColor = false;
//            // 
//            // rbWaveTypeNormalCurve
//            // 
//            this.rbWaveTypeNormalCurve.BackColor = System.Drawing.SystemColors.Control;
//            this.rbWaveTypeNormalCurve.Location = new System.Drawing.Point(277, 73);
//            this.rbWaveTypeNormalCurve.Name = "rbWaveTypeNormalCurve";
//            this.rbWaveTypeNormalCurve.Size = new System.Drawing.Size(89, 17);
//            this.rbWaveTypeNormalCurve.TabIndex = 136;
//            this.rbWaveTypeNormalCurve.Text = "Normal Curve";
//            this.rbWaveTypeNormalCurve.UseVisualStyleBackColor = false;
//            this.rbWaveTypeNormalCurve.Click += new System.EventHandler(this.rbWaveTypeNormalCurve_Click);
//            // 
//            // rbWaveTypeSawTooth
//            // 
//            this.rbWaveTypeSawTooth.BackColor = System.Drawing.SystemColors.Control;
//            this.rbWaveTypeSawTooth.Location = new System.Drawing.Point(277, 44);
//            this.rbWaveTypeSawTooth.Name = "rbWaveTypeSawTooth";
//            this.rbWaveTypeSawTooth.Size = new System.Drawing.Size(77, 17);
//            this.rbWaveTypeSawTooth.TabIndex = 135;
//            this.rbWaveTypeSawTooth.Text = "Saw-Tooth";
//            this.rbWaveTypeSawTooth.UseVisualStyleBackColor = false;
//            this.rbWaveTypeSawTooth.Click += new System.EventHandler(this.rbWaveTypeSawTooth_Click);
//            // 
//            // chkChangeCamera
//            // 
//            this.chkChangeCamera.AutoSize = true;
//            this.chkChangeCamera.Location = new System.Drawing.Point(33, 184);
//            this.chkChangeCamera.Name = "chkChangeCamera";
//            this.chkChangeCamera.Size = new System.Drawing.Size(171, 17);
//            this.chkChangeCamera.TabIndex = 130;
//            this.chkChangeCamera.Text = "Change Camera (Experimental)";
//            this.chkChangeCamera.UseVisualStyleBackColor = true;
//            // 
//            // chkLocalTimerEnabled
//            // 
//            this.chkLocalTimerEnabled.BackColor = System.Drawing.SystemColors.Control;
//            this.chkLocalTimerEnabled.Checked = true;
//            this.chkLocalTimerEnabled.CheckState = System.Windows.Forms.CheckState.Checked;
//            this.chkLocalTimerEnabled.Location = new System.Drawing.Point(33, 161);
//            this.chkLocalTimerEnabled.Name = "chkLocalTimerEnabled";
//            this.chkLocalTimerEnabled.Size = new System.Drawing.Size(167, 17);
//            this.chkLocalTimerEnabled.TabIndex = 128;
//            this.chkLocalTimerEnabled.Text = "Add with Local &Timer Enabled";
//            this.chkLocalTimerEnabled.UseVisualStyleBackColor = false;
//            // 
//            // label12
//            // 
//            this.label12.BackColor = System.Drawing.SystemColors.Control;
//            this.label12.Location = new System.Drawing.Point(67, 135);
//            this.label12.Name = "label12";
//            this.label12.Size = new System.Drawing.Size(27, 13);
//            this.label12.TabIndex = 125;
//            this.label12.Text = "Min:";
//            // 
//            // label13
//            // 
//            this.label13.BackColor = System.Drawing.SystemColors.Control;
//            this.label13.Location = new System.Drawing.Point(248, 135);
//            this.label13.Name = "label13";
//            this.label13.Size = new System.Drawing.Size(30, 13);
//            this.label13.TabIndex = 124;
//            this.label13.Text = "Max";
//            // 
//            // nudLifeTimeMax
//            // 
//            this.nudLifeTimeMax.DecimalPlaces = 1;
//            this.nudLifeTimeMax.Location = new System.Drawing.Point(172, 133);
//            this.nudLifeTimeMax.Maximum = new decimal(new int[] {
//            -1981284352,
//            -1966660860,
//            0,
//            0});
//            this.nudLifeTimeMax.Minimum = new decimal(new int[] {
//            1,
//            0,
//            0,
//            0});
//            this.nudLifeTimeMax.Name = "nudLifeTimeMax";
//            this.nudLifeTimeMax.Size = new System.Drawing.Size(70, 20);
//            this.nudLifeTimeMax.TabIndex = 123;
//            this.nudLifeTimeMax.ThousandsSeparator = true;
//            this.nudLifeTimeMax.Value = new decimal(new int[] {
//            1000,
//            0,
//            0,
//            0});
//            // 
//            // label2
//            // 
//            this.label2.BackColor = System.Drawing.SystemColors.Control;
//            this.label2.Location = new System.Drawing.Point(8, 140);
//            this.label2.Name = "label2";
//            this.label2.Size = new System.Drawing.Size(53, 13);
//            this.label2.TabIndex = 122;
//            this.label2.Text = "Life Time:";
//            // 
//            // nudLifeTimeMin
//            // 
//            this.nudLifeTimeMin.DecimalPlaces = 1;
//            this.nudLifeTimeMin.Location = new System.Drawing.Point(100, 133);
//            this.nudLifeTimeMin.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudLifeTimeMin.Minimum = new decimal(new int[] {
//            1,
//            0,
//            0,
//            0});
//            this.nudLifeTimeMin.Name = "nudLifeTimeMin";
//            this.nudLifeTimeMin.Size = new System.Drawing.Size(70, 20);
//            this.nudLifeTimeMin.TabIndex = 121;
//            this.nudLifeTimeMin.ThousandsSeparator = true;
//            this.nudLifeTimeMin.Value = new decimal(new int[] {
//            100,
//            0,
//            0,
//            0});
//            // 
//            // label14
//            // 
//            this.label14.BackColor = System.Drawing.SystemColors.Control;
//            this.label14.Location = new System.Drawing.Point(81, 111);
//            this.label14.Name = "label14";
//            this.label14.Size = new System.Drawing.Size(27, 13);
//            this.label14.TabIndex = 120;
//            this.label14.Text = "Min:";
//            // 
//            // label16
//            // 
//            this.label16.BackColor = System.Drawing.SystemColors.Control;
//            this.label16.Location = new System.Drawing.Point(226, 111);
//            this.label16.Name = "label16";
//            this.label16.Size = new System.Drawing.Size(30, 13);
//            this.label16.TabIndex = 119;
//            this.label16.Text = "Max";
//            // 
//            // nudAmplitudeMax
//            // 
//            this.nudAmplitudeMax.DecimalPlaces = 1;
//            this.nudAmplitudeMax.Location = new System.Drawing.Point(168, 107);
//            this.nudAmplitudeMax.Maximum = new decimal(new int[] {
//            1000,
//            0,
//            0,
//            0});
//            this.nudAmplitudeMax.Minimum = new decimal(new int[] {
//            1000,
//            0,
//            0,
//            -2147483648});
//            this.nudAmplitudeMax.Name = "nudAmplitudeMax";
//            this.nudAmplitudeMax.Size = new System.Drawing.Size(52, 20);
//            this.nudAmplitudeMax.TabIndex = 118;
//            this.nudAmplitudeMax.Value = new decimal(new int[] {
//            50,
//            0,
//            0,
//            0});
//            // 
//            // lblDesc_Amplitude
//            // 
//            this.lblDesc_Amplitude.BackColor = System.Drawing.SystemColors.Control;
//            this.lblDesc_Amplitude.Location = new System.Drawing.Point(4, 114);
//            this.lblDesc_Amplitude.Name = "lblDesc_Amplitude";
//            this.lblDesc_Amplitude.Size = new System.Drawing.Size(56, 13);
//            this.lblDesc_Amplitude.TabIndex = 117;
//            this.lblDesc_Amplitude.Text = "Amplitude:";
//            // 
//            // nudAmplitudeMin
//            // 
//            this.nudAmplitudeMin.DecimalPlaces = 1;
//            this.nudAmplitudeMin.Location = new System.Drawing.Point(114, 107);
//            this.nudAmplitudeMin.Maximum = new decimal(new int[] {
//            1000,
//            0,
//            0,
//            0});
//            this.nudAmplitudeMin.Minimum = new decimal(new int[] {
//            1000,
//            0,
//            0,
//            -2147483648});
//            this.nudAmplitudeMin.Name = "nudAmplitudeMin";
//            this.nudAmplitudeMin.Size = new System.Drawing.Size(52, 20);
//            this.nudAmplitudeMin.TabIndex = 116;
//            this.nudAmplitudeMin.Value = new decimal(new int[] {
//            11,
//            0,
//            0,
//            65536});
//            // 
//            // label19
//            // 
//            this.label19.Font = new System.Drawing.Font("Microsoft Sans Serif", 6F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
//            this.label19.Location = new System.Drawing.Point(223, 60);
//            this.label19.Name = "label19";
//            this.label19.Size = new System.Drawing.Size(10, 9);
//            this.label19.TabIndex = 115;
//            this.label19.Text = "Z";
//            // 
//            // label20
//            // 
//            this.label20.Font = new System.Drawing.Font("Microsoft Sans Serif", 6F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
//            this.label20.Location = new System.Drawing.Point(147, 60);
//            this.label20.Name = "label20";
//            this.label20.Size = new System.Drawing.Size(10, 9);
//            this.label20.TabIndex = 114;
//            this.label20.Text = "Y";
//            // 
//            // label21
//            // 
//            this.label21.Font = new System.Drawing.Font("Microsoft Sans Serif", 6F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
//            this.label21.Location = new System.Drawing.Point(67, 60);
//            this.label21.Name = "label21";
//            this.label21.Size = new System.Drawing.Size(10, 9);
//            this.label21.TabIndex = 113;
//            this.label21.Text = "X";
//            // 
//            // label11
//            // 
//            this.label11.Font = new System.Drawing.Font("Microsoft Sans Serif", 6F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
//            this.label11.Location = new System.Drawing.Point(223, 27);
//            this.label11.Name = "label11";
//            this.label11.Size = new System.Drawing.Size(14, 10);
//            this.label11.TabIndex = 112;
//            this.label11.Text = "Z";
//            // 
//            // label10
//            // 
//            this.label10.Font = new System.Drawing.Font("Microsoft Sans Serif", 6F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
//            this.label10.Location = new System.Drawing.Point(147, 27);
//            this.label10.Name = "label10";
//            this.label10.Size = new System.Drawing.Size(14, 10);
//            this.label10.TabIndex = 111;
//            this.label10.Text = "Y";
//            // 
//            // label9
//            // 
//            this.label9.Font = new System.Drawing.Font("Microsoft Sans Serif", 6F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
//            this.label9.Location = new System.Drawing.Point(67, 27);
//            this.label9.Name = "label9";
//            this.label9.Size = new System.Drawing.Size(14, 10);
//            this.label9.TabIndex = 110;
//            this.label9.Text = "X";
//            // 
//            // nudXMax
//            // 
//            this.nudXMax.DecimalPlaces = 3;
//            this.nudXMax.Location = new System.Drawing.Point(33, 70);
//            this.nudXMax.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudXMax.Minimum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            -2147483648});
//            this.nudXMax.Name = "nudXMax";
//            this.nudXMax.Size = new System.Drawing.Size(70, 20);
//            this.nudXMax.TabIndex = 107;
//            this.nudXMax.ThousandsSeparator = true;
//            // 
//            // nudYMax
//            // 
//            this.nudYMax.DecimalPlaces = 3;
//            this.nudYMax.Location = new System.Drawing.Point(109, 70);
//            this.nudYMax.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudYMax.Minimum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            -2147483648});
//            this.nudYMax.Name = "nudYMax";
//            this.nudYMax.Size = new System.Drawing.Size(70, 20);
//            this.nudYMax.TabIndex = 108;
//            this.nudYMax.ThousandsSeparator = true;
//            // 
//            // nudZMax
//            // 
//            this.nudZMax.DecimalPlaces = 3;
//            this.nudZMax.Location = new System.Drawing.Point(185, 70);
//            this.nudZMax.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudZMax.Minimum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            -2147483648});
//            this.nudZMax.Name = "nudZMax";
//            this.nudZMax.Size = new System.Drawing.Size(70, 20);
//            this.nudZMax.TabIndex = 109;
//            this.nudZMax.ThousandsSeparator = true;
//            // 
//            // nudXMin
//            // 
//            this.nudXMin.DecimalPlaces = 3;
//            this.nudXMin.Location = new System.Drawing.Point(33, 39);
//            this.nudXMin.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudXMin.Minimum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            -2147483648});
//            this.nudXMin.Name = "nudXMin";
//            this.nudXMin.Size = new System.Drawing.Size(70, 20);
//            this.nudXMin.TabIndex = 104;
//            this.nudXMin.ThousandsSeparator = true;
//            // 
//            // nudYMin
//            // 
//            this.nudYMin.DecimalPlaces = 3;
//            this.nudYMin.Location = new System.Drawing.Point(109, 39);
//            this.nudYMin.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudYMin.Minimum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            -2147483648});
//            this.nudYMin.Name = "nudYMin";
//            this.nudYMin.Size = new System.Drawing.Size(70, 20);
//            this.nudYMin.TabIndex = 105;
//            this.nudYMin.ThousandsSeparator = true;
//            // 
//            // nudZMin
//            // 
//            this.nudZMin.DecimalPlaces = 3;
//            this.nudZMin.Location = new System.Drawing.Point(185, 39);
//            this.nudZMin.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudZMin.Minimum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            -2147483648});
//            this.nudZMin.Name = "nudZMin";
//            this.nudZMin.Size = new System.Drawing.Size(70, 20);
//            this.nudZMin.TabIndex = 106;
//            this.nudZMin.ThousandsSeparator = true;
//            // 
//            // label5
//            // 
//            this.label5.BackColor = System.Drawing.SystemColors.Control;
//            this.label5.Location = new System.Drawing.Point(5, 44);
//            this.label5.Name = "label5";
//            this.label5.Size = new System.Drawing.Size(27, 13);
//            this.label5.TabIndex = 103;
//            this.label5.Text = "Min:";
//            // 
//            // label4
//            // 
//            this.label4.BackColor = System.Drawing.SystemColors.Control;
//            this.label4.Location = new System.Drawing.Point(5, 75);
//            this.label4.Name = "label4";
//            this.label4.Size = new System.Drawing.Size(30, 13);
//            this.label4.TabIndex = 102;
//            this.label4.Text = "Max:";
//            // 
//            // lblDesc_CenterPosition
//            // 
//            this.lblDesc_CenterPosition.BackColor = System.Drawing.SystemColors.Control;
//            this.lblDesc_CenterPosition.Location = new System.Drawing.Point(75, 7);
//            this.lblDesc_CenterPosition.Name = "lblDesc_CenterPosition";
//            this.lblDesc_CenterPosition.Size = new System.Drawing.Size(78, 13);
//            this.lblDesc_CenterPosition.TabIndex = 101;
//            this.lblDesc_CenterPosition.Text = "Center Position";
//            // 
//            // tpSinAndCos
//            // 
//            this.tpSinAndCos.Controls.Add(this.label23);
//            this.tpSinAndCos.Controls.Add(this.label22);
//            this.tpSinAndCos.Controls.Add(this.nudFrequencyMax);
//            this.tpSinAndCos.Controls.Add(this.nudFrequencyMin);
//            this.tpSinAndCos.Controls.Add(this.label7);
//            this.tpSinAndCos.Controls.Add(this.label15);
//            this.tpSinAndCos.Controls.Add(this.nudFixedWaveCount);
//            this.tpSinAndCos.Location = new System.Drawing.Point(4, 22);
//            this.tpSinAndCos.Name = "tpSinAndCos";
//            this.tpSinAndCos.Size = new System.Drawing.Size(379, 216);
//            this.tpSinAndCos.TabIndex = 3;
//            this.tpSinAndCos.Text = "Sin and Cos";
//            this.tpSinAndCos.UseVisualStyleBackColor = true;
//            // 
//            // label23
//            // 
//            this.label23.BackColor = System.Drawing.SystemColors.Control;
//            this.label23.Location = new System.Drawing.Point(61, 8);
//            this.label23.Name = "label23";
//            this.label23.Size = new System.Drawing.Size(27, 13);
//            this.label23.TabIndex = 108;
//            this.label23.Text = "Min:";
//            // 
//            // label22
//            // 
//            this.label22.BackColor = System.Drawing.SystemColors.Control;
//            this.label22.Location = new System.Drawing.Point(241, 6);
//            this.label22.Name = "label22";
//            this.label22.Size = new System.Drawing.Size(30, 13);
//            this.label22.TabIndex = 107;
//            this.label22.Text = "Max";
//            // 
//            // nudFrequencyMax
//            // 
//            this.nudFrequencyMax.DecimalPlaces = 3;
//            this.nudFrequencyMax.Increment = new decimal(new int[] {
//            1,
//            0,
//            0,
//            65536});
//            this.nudFrequencyMax.Location = new System.Drawing.Point(165, 4);
//            this.nudFrequencyMax.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudFrequencyMax.Name = "nudFrequencyMax";
//            this.nudFrequencyMax.Size = new System.Drawing.Size(70, 20);
//            this.nudFrequencyMax.TabIndex = 106;
//            this.nudFrequencyMax.ThousandsSeparator = true;
//            this.nudFrequencyMax.Value = new decimal(new int[] {
//            1,
//            0,
//            0,
//            131072});
//            // 
//            // nudFrequencyMin
//            // 
//            this.nudFrequencyMin.DecimalPlaces = 3;
//            this.nudFrequencyMin.Increment = new decimal(new int[] {
//            1,
//            0,
//            0,
//            65536});
//            this.nudFrequencyMin.Location = new System.Drawing.Point(94, 3);
//            this.nudFrequencyMin.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudFrequencyMin.Name = "nudFrequencyMin";
//            this.nudFrequencyMin.Size = new System.Drawing.Size(70, 20);
//            this.nudFrequencyMin.TabIndex = 105;
//            this.nudFrequencyMin.ThousandsSeparator = true;
//            this.nudFrequencyMin.Value = new decimal(new int[] {
//            1,
//            0,
//            0,
//            196608});
//            // 
//            // label7
//            // 
//            this.label7.BackColor = System.Drawing.SystemColors.Control;
//            this.label7.Location = new System.Drawing.Point(3, 7);
//            this.label7.Name = "label7";
//            this.label7.Size = new System.Drawing.Size(65, 17);
//            this.label7.TabIndex = 104;
//            this.label7.Text = "Frequency:";
//            // 
//            // label15
//            // 
//            this.label15.AutoSize = true;
//            this.label15.ForeColor = System.Drawing.SystemColors.ControlText;
//            this.label15.Location = new System.Drawing.Point(18, 42);
//            this.label15.Name = "label15";
//            this.label15.Size = new System.Drawing.Size(70, 13);
//            this.label15.TabIndex = 75;
//            this.label15.Text = "Wave Count:";
//            this.label15.Visible = false;
//            // 
//            // nudFixedWaveCount
//            // 
//            this.nudFixedWaveCount.DecimalPlaces = 2;
//            this.nudFixedWaveCount.ForeColor = System.Drawing.SystemColors.ControlText;
//            this.nudFixedWaveCount.Location = new System.Drawing.Point(94, 35);
//            this.nudFixedWaveCount.Maximum = new decimal(new int[] {
//            1000,
//            0,
//            0,
//            0});
//            this.nudFixedWaveCount.Minimum = new decimal(new int[] {
//            1,
//            0,
//            0,
//            196608});
//            this.nudFixedWaveCount.Name = "nudFixedWaveCount";
//            this.nudFixedWaveCount.Size = new System.Drawing.Size(73, 20);
//            this.nudFixedWaveCount.TabIndex = 74;
//            this.nudFixedWaveCount.Value = new decimal(new int[] {
//            1,
//            0,
//            0,
//            0});
//            this.nudFixedWaveCount.Visible = false;
//            // 
//            // tpNormal
//            // 
//            this.tpNormal.Controls.Add(this.label6);
//            this.tpNormal.Controls.Add(this.label25);
//            this.tpNormal.Controls.Add(this.nudNormalVarianceMax);
//            this.tpNormal.Controls.Add(this.nudRadialSpeedMax);
//            this.tpNormal.Controls.Add(this.nudR0Max);
//            this.tpNormal.Controls.Add(this.nudLengthOfEffectMax);
//            this.tpNormal.Controls.Add(this.label24);
//            this.tpNormal.Controls.Add(this.nudNormalVarianceMin);
//            this.tpNormal.Controls.Add(this.label8);
//            this.tpNormal.Controls.Add(this.nudRadialSpeedMin);
//            this.tpNormal.Controls.Add(this.nudR0Min);
//            this.tpNormal.Controls.Add(this.nudLengthOfEffectMin);
//            this.tpNormal.Controls.Add(this.lblDescLengthOfEffect);
//            this.tpNormal.Controls.Add(this.label1);
//            this.tpNormal.Location = new System.Drawing.Point(4, 22);
//            this.tpNormal.Name = "tpNormal";
//            this.tpNormal.Size = new System.Drawing.Size(379, 216);
//            this.tpNormal.TabIndex = 4;
//            this.tpNormal.Text = "Normal Wave";
//            this.tpNormal.UseVisualStyleBackColor = true;
//            // 
//            // label6
//            // 
//            this.label6.BackColor = System.Drawing.SystemColors.Control;
//            this.label6.Location = new System.Drawing.Point(147, 4);
//            this.label6.Name = "label6";
//            this.label6.Size = new System.Drawing.Size(27, 13);
//            this.label6.TabIndex = 146;
//            this.label6.Text = "Min:";
//            // 
//            // label25
//            // 
//            this.label25.BackColor = System.Drawing.SystemColors.Control;
//            this.label25.Location = new System.Drawing.Point(220, 4);
//            this.label25.Name = "label25";
//            this.label25.Size = new System.Drawing.Size(30, 13);
//            this.label25.TabIndex = 145;
//            this.label25.Text = "Max";
//            // 
//            // nudNormalVarianceMax
//            // 
//            this.nudNormalVarianceMax.DecimalPlaces = 3;
//            this.nudNormalVarianceMax.Increment = new decimal(new int[] {
//            1,
//            0,
//            0,
//            65536});
//            this.nudNormalVarianceMax.Location = new System.Drawing.Point(180, 83);
//            this.nudNormalVarianceMax.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudNormalVarianceMax.Name = "nudNormalVarianceMax";
//            this.nudNormalVarianceMax.Size = new System.Drawing.Size(70, 20);
//            this.nudNormalVarianceMax.TabIndex = 144;
//            this.nudNormalVarianceMax.ThousandsSeparator = true;
//            this.nudNormalVarianceMax.Value = new decimal(new int[] {
//            6,
//            0,
//            0,
//            0});
//            // 
//            // nudRadialSpeedMax
//            // 
//            this.nudRadialSpeedMax.Location = new System.Drawing.Point(197, 122);
//            this.nudRadialSpeedMax.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudRadialSpeedMax.Name = "nudRadialSpeedMax";
//            this.nudRadialSpeedMax.Size = new System.Drawing.Size(53, 20);
//            this.nudRadialSpeedMax.TabIndex = 143;
//            this.nudRadialSpeedMax.ThousandsSeparator = true;
//            this.nudRadialSpeedMax.Value = new decimal(new int[] {
//            25,
//            0,
//            0,
//            0});
//            // 
//            // nudR0Max
//            // 
//            this.nudR0Max.DecimalPlaces = 1;
//            this.nudR0Max.Location = new System.Drawing.Point(180, 20);
//            this.nudR0Max.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudR0Max.Name = "nudR0Max";
//            this.nudR0Max.Size = new System.Drawing.Size(70, 20);
//            this.nudR0Max.TabIndex = 141;
//            this.nudR0Max.ThousandsSeparator = true;
//            this.nudR0Max.Value = new decimal(new int[] {
//            100,
//            0,
//            0,
//            0});
//            // 
//            // nudLengthOfEffectMax
//            // 
//            this.nudLengthOfEffectMax.DecimalPlaces = 1;
//            this.nudLengthOfEffectMax.Location = new System.Drawing.Point(180, 50);
//            this.nudLengthOfEffectMax.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudLengthOfEffectMax.Minimum = new decimal(new int[] {
//            1,
//            0,
//            0,
//            327680});
//            this.nudLengthOfEffectMax.Name = "nudLengthOfEffectMax";
//            this.nudLengthOfEffectMax.Size = new System.Drawing.Size(70, 20);
//            this.nudLengthOfEffectMax.TabIndex = 142;
//            this.nudLengthOfEffectMax.ThousandsSeparator = true;
//            this.nudLengthOfEffectMax.Value = new decimal(new int[] {
//            200,
//            0,
//            0,
//            0});
//            // 
//            // label24
//            // 
//            this.label24.BackColor = System.Drawing.SystemColors.Control;
//            this.label24.Location = new System.Drawing.Point(15, 90);
//            this.label24.Name = "label24";
//            this.label24.Size = new System.Drawing.Size(53, 13);
//            this.label24.TabIndex = 140;
//            this.label24.Text = "Variance:";
//            // 
//            // nudNormalVarianceMin
//            // 
//            this.nudNormalVarianceMin.DecimalPlaces = 3;
//            this.nudNormalVarianceMin.Increment = new decimal(new int[] {
//            1,
//            0,
//            0,
//            65536});
//            this.nudNormalVarianceMin.Location = new System.Drawing.Point(104, 83);
//            this.nudNormalVarianceMin.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudNormalVarianceMin.Name = "nudNormalVarianceMin";
//            this.nudNormalVarianceMin.Size = new System.Drawing.Size(70, 20);
//            this.nudNormalVarianceMin.TabIndex = 139;
//            this.nudNormalVarianceMin.ThousandsSeparator = true;
//            this.nudNormalVarianceMin.Value = new decimal(new int[] {
//            1,
//            0,
//            0,
//            65536});
//            // 
//            // label8
//            // 
//            this.label8.BackColor = System.Drawing.SystemColors.Control;
//            this.label8.Location = new System.Drawing.Point(15, 129);
//            this.label8.Name = "label8";
//            this.label8.Size = new System.Drawing.Size(103, 13);
//            this.label8.TabIndex = 138;
//            this.label8.Text = "Radial Wave Speed";
//            // 
//            // nudRadialSpeedMin
//            // 
//            this.nudRadialSpeedMin.Location = new System.Drawing.Point(121, 122);
//            this.nudRadialSpeedMin.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudRadialSpeedMin.Name = "nudRadialSpeedMin";
//            this.nudRadialSpeedMin.Size = new System.Drawing.Size(53, 20);
//            this.nudRadialSpeedMin.TabIndex = 137;
//            this.nudRadialSpeedMin.ThousandsSeparator = true;
//            this.nudRadialSpeedMin.Value = new decimal(new int[] {
//            10,
//            0,
//            0,
//            0});
//            // 
//            // nudR0Min
//            // 
//            this.nudR0Min.DecimalPlaces = 1;
//            this.nudR0Min.Location = new System.Drawing.Point(104, 20);
//            this.nudR0Min.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudR0Min.Name = "nudR0Min";
//            this.nudR0Min.Size = new System.Drawing.Size(70, 20);
//            this.nudR0Min.TabIndex = 133;
//            this.nudR0Min.ThousandsSeparator = true;
//            this.nudR0Min.Value = new decimal(new int[] {
//            10,
//            0,
//            0,
//            0});
//            // 
//            // nudLengthOfEffectMin
//            // 
//            this.nudLengthOfEffectMin.DecimalPlaces = 1;
//            this.nudLengthOfEffectMin.Location = new System.Drawing.Point(104, 50);
//            this.nudLengthOfEffectMin.Maximum = new decimal(new int[] {
//            10000,
//            0,
//            0,
//            0});
//            this.nudLengthOfEffectMin.Minimum = new decimal(new int[] {
//            1,
//            0,
//            0,
//            327680});
//            this.nudLengthOfEffectMin.Name = "nudLengthOfEffectMin";
//            this.nudLengthOfEffectMin.Size = new System.Drawing.Size(70, 20);
//            this.nudLengthOfEffectMin.TabIndex = 136;
//            this.nudLengthOfEffectMin.ThousandsSeparator = true;
//            this.nudLengthOfEffectMin.Value = new decimal(new int[] {
//            10,
//            0,
//            0,
//            0});
//            // 
//            // lblDescLengthOfEffect
//            // 
//            this.lblDescLengthOfEffect.BackColor = System.Drawing.SystemColors.Control;
//            this.lblDescLengthOfEffect.Location = new System.Drawing.Point(15, 57);
//            this.lblDescLengthOfEffect.Name = "lblDescLengthOfEffect";
//            this.lblDescLengthOfEffect.Size = new System.Drawing.Size(83, 13);
//            this.lblDescLengthOfEffect.TabIndex = 135;
//            this.lblDescLengthOfEffect.Text = "Length of Effect";
//            // 
//            // label1
//            // 
//            this.label1.BackColor = System.Drawing.SystemColors.Control;
//            this.label1.Location = new System.Drawing.Point(13, 20);
//            this.label1.Name = "label1";
//            this.label1.Size = new System.Drawing.Size(81, 33);
//            this.label1.TabIndex = 134;
//            this.label1.Text = "Radial Length at Start Time";
//            // 
//            // FluidOld
//            // 
//            this.ClientSize = new System.Drawing.Size(596, 570);
//            this.Controls.Add(this.splitContainer1);
//            this.Name = "FluidOld";
//            this.Text = "FluidOld and Wave Editor";
//            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FluidOld_FormClosing);
//            this.splitContainer1.Panel1.ResumeLayout(false);
//            this.splitContainer1.Panel1.PerformLayout();
//            this.splitContainer1.Panel2.ResumeLayout(false);
//            this.splitContainer1.ResumeLayout(false);
//            ((System.ComponentModel.ISupportInitialize)(this.nudGlobalTime)).EndInit();
//            this.scWaves.Panel1.ResumeLayout(false);
//            this.scWaves.Panel1.PerformLayout();
//            this.scWaves.Panel2.ResumeLayout(false);
//            this.scWaves.ResumeLayout(false);
//            ((System.ComponentModel.ISupportInitialize)(this.nudCount)).EndInit();
//            this.tabControl1.ResumeLayout(false);
//            this.tpGeneral.ResumeLayout(false);
//            this.tpGeneral.PerformLayout();
//            ((System.ComponentModel.ISupportInitialize)(this.nudLifeTimeMax)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudLifeTimeMin)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudAmplitudeMax)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudAmplitudeMin)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudXMax)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudYMax)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudZMax)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudXMin)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudYMin)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudZMin)).EndInit();
//            this.tpSinAndCos.ResumeLayout(false);
//            this.tpSinAndCos.PerformLayout();
//            ((System.ComponentModel.ISupportInitialize)(this.nudFrequencyMax)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudFrequencyMin)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudFixedWaveCount)).EndInit();
//            this.tpNormal.ResumeLayout(false);
//            ((System.ComponentModel.ISupportInitialize)(this.nudNormalVarianceMax)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudRadialSpeedMax)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudR0Max)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudLengthOfEffectMax)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudNormalVarianceMin)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudRadialSpeedMin)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudR0Min)).EndInit();
//            ((System.ComponentModel.ISupportInitialize)(this.nudLengthOfEffectMin)).EndInit();
//            this.ResumeLayout(false);

//        }

//        #endregion "Designer Generated - InitializeComponent"


        public FluidOld(Device device, ManagedRenderer rendManager, DirectXForm formForHandlers)
		{
            Initialize(device, rendManager, formForHandlers);
            Recreate();
        }

		protected DirectXForm mFormForHandlers;

		public void Initialize(Device device, ManagedRenderer rendManager, DirectXForm formForHandlers)
        {
            InitializeComponent();
            position = new Vector3(0, 0, 0);

			mFormForHandlers = formForHandlers;
			mFormForHandlers.MouseDown += new MouseEventHandler(mFormForHandlers_MouseDown);

            InitializeNUDValues();

            InitializeMaterial();
            renderer = rendManager;
            mDevice = device; //set before registering for sure...

            InitializeParticles();
            mWaves = new List<IEquilibriumWave3d>();
			mWaveListItems = new List<ObjectListItem>();

            //AddRandomWavesSameWay();
            Register();
            pgSelfViewer.SelectedObject = this;

            pgSelfViewer.BrowsableAttributes = new System.ComponentModel.AttributeCollection( new PGBrowsableAttribute());


		}

		void mFormForHandlers_MouseDown(object sender, MouseEventArgs e)
		{
			
			//throw new NotImplementedException();
			if (this.GlobalTimerEnabled && e.Button == MouseButtons.Middle)
			{
				DoAddWave(true, 0, 0);
			}
		}

        public void InitializeNUDValues()
        {
            //float x = xMin + (xMax - xMin) / 2, y = 0, z = zMax;
			//nudAmplitudeMax.Value = 10;
			//nudAmplitudeMin.Value = 5;
			//nudCount.Value = 1;
			//nudLifeTimeMax.Value = 60;
			//nudLifeTimeMin.Value = 50;
            
            decimal xhalf = (decimal)(xMin + (xMax - xMin) / 2);

			nudXMin.Value = (decimal)xMin;
			nudXMax.Value = (decimal)xMax;

			nudYMin.Value = (decimal)yMin;
			nudYMax.Value = (decimal)yMax; 

        }
		public FluidOld(Device device, ManagedRenderer rendManager, DirectXForm formForHandlers, float xmin, float xmax, int x_count, float ymin, float ymax, int y_count, float zmin, float zmax, bool createData)
		{

			xMin = xmin; xMax = xmax; 
			yMin = ymin; yMax = ymax; 
			zMin = zmin; zMax = zmax;
			xCount = x_count;
			yCount = y_count;
			//zCount = z_count;
			Initialize(device, rendManager, formForHandlers);
			if (createData)
				Recreate();
		}

		public void InitializeParticles()
		{
			int x_count = xCount, y_count = yCount, z_count = zCount; //cache for safe use (no changing while this function is working)
			int ParticleIndex = 0;
			mParticles = new EquilibriumPoint[x_count, y_count, z_count];

			for (int xidx = 0; xidx < x_count; xidx++)
			{
				for (int yidx = 0; yidx < y_count; yidx++)
				{
					for (int zidx = 0; zidx < z_count; zidx++)
					{
						EquilibriumPoint p = new EquilibriumPoint(new Vector3((float)xidx / (float)x_count * (xMax - xMin) + xMin, (float)yidx / (float)y_count * (yMax - yMin) + yMin, (float)zidx / (float)z_count * (zMax - zMin) + zMin));
						p.Index = ParticleIndex;
						mParticles[xidx, yidx, zidx] = p;
						
						ParticleIndex++;
					}
				}
			}
		}

		public void RemoveAllWaves()
		{
			//mVerticalWaves.Clear(); mHorizontalWaves.Clear(); 
			mWaves.Clear();
		}
	
		//float mAllHeight = 1f;
		//public float AllWavesHeight
		//{
		//    get {return mAllHeight;}
		//    set
		//    {
		//        mAllHeight = value;
		//        List<EquilibriumWave3d> latWaves = LateralWaves;
		//        List<EquilibriumWave3d> horWaves = HorizontalWaves;
		//        List<EquilibriumWave3d> verWaves = VerticalWaves;
		//        foreach (EquilibriumWave3d w in latWaves)
		//        {
		//            w.Cx = value; w.Cy = value; w.Cz = value;
		//        }
		//        foreach (EquilibriumWave3d w in horWaves)
		//        {
		//            w.Cx = value; w.Cy = value; w.Cz = value;
		//        }
		//        foreach (EquilibriumWave3d w in verWaves)
		//        {
		//            w.Cx = value; w.Cy = value; w.Cz = value;
		//        }
		//    }
		//}
        [PGBrowsableAttribute]
        public double Time
		{
			get { return mTime; }
			set { 
				mTime = value;
				initializing = true;
				nudGlobalTime.Value = (decimal)mTime; 
				nudGlobalTime.Update();
				initializing = false;
			}
		}
        ///SetTimedVertexData
		protected float dTime = .03f;
        [PGBrowsableAttribute]
		public float DTime
		{
			get { return dTime; }
			set { dTime = value; }
		}

		protected EquilibriumPoint[, ,] mParticles = null;

		////private int[] mIndexData = null;
		//List<EquilibriumWave3d> mHorizontalWaves = null;

		//[PGBrowsable]
		//public List<EquilibriumWave3d> HorizontalWaves
		//{
		//    get { return mHorizontalWaves; }
		//    set { mHorizontalWaves = value; }
		//}

		List<IEquilibriumWave3d> mWaves = null;
        [PGBrowsableAttribute]
		public List<IEquilibriumWave3d> Waves
		{
			get { return mWaves; }
			set { mWaves = value; }
		}

		private List<ObjectListItem> mWaveListItems = null;

		protected List<ObjectListItem> WaveListItems
		{
			get { return mWaveListItems; }
			set { mWaveListItems = value; }
		}
		
		//List<EquilibriumWave3d> mVerticalWaves = null;
		//[PGBrowsable]
		//public List<EquilibriumWave3d> VerticalWaves
		//{
		//    get { return mVerticalWaves; }
		//    set { mVerticalWaves = value; }
		//}
		//public static Vector3 ForceField(float x, float y, float z)
		//{
		//   return 
		//}

		//Vector3[, ,] displacementField;
		public bool near(float lX, float value)
		{
			return (lX - value) < .1f;
		}
		/// <summary>
		/// 
		/// </summary>
		Buoy onlyBuoy;

		float zMaxDisplacement = 0;
		[PGBrowsableAttribute]
		public float ZMaxDisplacement
		{
			get { return zMaxDisplacement; }
		}

		float zMinDisplacement = 0;
		[PGBrowsableAttribute]
		public float ZMinDisplacement
		{
			get { return zMinDisplacement; }
		}

		Vector2 desiredBuoyPos = new Vector2(100, 100);

		/// <summary>
		/// 
		/// </summary>
		public void GetDisplacementField()
		{
			zMaxDisplacement = 0;
			zMinDisplacement = 0;

			if (onlyBuoy == null)
				onlyBuoy = new Buoy(mDevice, renderer);

			EquilibriumPoint particle = onlyBuoy.AssociatedParticle;

			int zidx = 0;
			for (int xidx = 0; xidx < mParticles.GetUpperBound(0) + 1; xidx++)
            {
				for (int yidx = 0; yidx < mParticles.GetUpperBound(1) + 1; yidx++)
				{
					for (zidx = 0; zidx < mParticles.GetUpperBound(2) + 1; zidx++)
					{
						Vector3 pos3 = mParticles[xidx, yidx, zidx].Position0;
						Vector2 pos2 = new Vector2(pos3.X, pos3.Y);

						Vector3 d = new Vector3(0f, 0f, 0f);

						SVector tdz = new SVector(0, 0, 0, Color.Orange);   //color overridden later

						foreach (IEquilibriumWave3d lsw in mWaves)
						{

							lsw.SetTime((float)Time);
							tdz = lsw.displacement(pos2);
							d = d + tdz.Position;
						}
						//dont yet do dz

						//if (d.Length() > 0)
						//	Debug.WriteLine("See this... " + d.Length());

						mParticles[xidx, yidx, zidx].Displacement = d;

						if (d.Z > zMaxDisplacement)
							zMaxDisplacement = d.Z;
						if (d.Z < zMinDisplacement)
							zMinDisplacement = d.Z;


						if (mWaves.Count != 0)
							mParticles[xidx, yidx, zidx].Color = tdz.Color;	//color may be overidden

						zidx = 0;

						//set buoy!!!!
						if (particle == null)
							particle = mParticles[xidx, yidx, zidx];
						else
						{
							//after setting displacement the only bouy
							Vector2 buoyXYPos;
							EquilibriumPoint associatedEPoint= onlyBuoy.AssociatedParticle;
							if (associatedEPoint != null)
								buoyXYPos = new Vector2(associatedEPoint.Position.X, associatedEPoint.Position.Y);
							else
								buoyXYPos = new Vector2(particle.Position.X, particle.Position.Y);

							Vector2 dNew2Diff = pos2 - desiredBuoyPos;
							Vector2 dOld2Diff = buoyXYPos - desiredBuoyPos;

							//if (mParticles[xidx, yidx, zidx].Index == onlyBuoy.AssociatedParticle.Index)
							//{
							//    onlyBuoy.Position.Z = 
							//}
							float dNew2DiffLen = dNew2Diff.Length();
							float dOld2DiffLen = dOld2Diff.Length();
							if ((dNew2DiffLen < dOld2DiffLen && dNew2DiffLen <= abs(xMax - xMin)/xCount))
							{
								particle = mParticles[xidx, yidx, zidx];
							}
							//else if (mParticles[xidx, yidx, zidx].Index == particle.Index)
							//	particle = mParticles[xidx, yidx, zidx];

						}
					}
				}
            }

		onlyBuoy.AssociatedParticle = particle;
		onlyBuoy.MaxZ = zMaxDisplacement;
			//RemoveDistantWaves();

			//return displacementField;
		}
		
		private void RemoveDistantWaves()
		{
			//now remove waves that arent doing much

			List<IEquilibriumWave3d> mLateralWavesToRemove = new List<IEquilibriumWave3d>();

			foreach (IEquilibriumWave3d lsw in mWaves)
			{
                if (lsw.PastLifeTime((float)Time))
					mLateralWavesToRemove.Add(lsw);
			}
			foreach (IEquilibriumWave3d mlwToRemove in mLateralWavesToRemove)
				mWaves.Remove(mlwToRemove);

			Debug.WriteLine("t: " + Time.ToString() + ", wcount:" + mWaves.Count.ToString());

		}


		public static Random r = new Random(0);

		public static float rndf(float min, float max)
		{
			int digitsAccuracy = 6;
			float f = 10 ^ digitsAccuracy;
			return r.Next((int)(min * f), (int)(max * f))/ (float)f;
		}

		private const int digitsAccuracy = 9;
		public static decimal f = 10 ^ digitsAccuracy;

        public static decimal rnddec(decimal min, decimal max)
        {
			if (min >= max)
			{
				decimal temp = min;
				min = max;
				max = temp;
			}
			return r.Next((int)(min * f), (int)(max * f)) / (decimal)f;
        }
		
		static int imax(int a, int b)
		{
			return a > b ? a : b;
		}
		static int imin(int a, int b)
		{
			return a < b ? a : b;
		}
		static float min(float a, float b)
		{
			return a < b ? a : b;
		}
		static float max(float a, float b)
		{
			return a > b ? a : b;
		}

		static float abs(float t)
		{
			return ( t >= 0 ? t : -t);
		}
		public Color GetColorForWater()
		{
			return Color.FromArgb(145, MainVertexColor);
		}
		public Color GetColorFromZ_LighterTop(EquilibriumPoint p)
		{
			float MaxDZ = zMaxDisplacement;
			float MinDZ = zMinDisplacement;
			//if (p.Displacement.LengthSq() > .001)
			//Debug.WriteLine("Stop here: p.Displacement.Length = " + p.Displacement.Length());

			//BEGIN: more blue based on height
			//float zRatio = min(1, abs(p.Position.Z / MaxDZ));
			//int zBase = 100;
			//int zScaled = imin(255, imax(0, (int)((255 - zBase) * (zRatio)) + zBase));
			//Color c = Color.FromArgb(zScaled, 0, (int)(zRatio / 10f * 255f), zScaled);
			//END: more blue based on height

			//whiter the higher
			float dif = abs(MinDZ - MaxDZ);
			float pzRatio;
			if (dif == 0)
			{
				pzRatio = 1;
			}
			else
			{
				pzRatio = abs(MinDZ - p.Displacement.Z) / dif;//max(0, min(1, min(MaxDZ, p.Displacement / MaxDZ))) * 10f / 10f;
			}
			//int whiteThreshold = 10;
			//int WhiteDifference = 255 - whiteThreshold;
			//int z255 = whiteThreshold * (int)pzRatio;
			//if (z255 <= 0)
			//    z255 = 0;
			//else if (z255 > whiteThreshold)
			//    z255 = whiteThreshold;

			Color baseColor = MainVertexColor;
			int a = (int)(245 + 10 * pzRatio );// baseColor.A;
			float colorRatio = (1f - .3f * pzRatio);
			int r = (int)(((float)baseColor.R) * colorRatio);
			int g = (int)(((float)baseColor.G) * colorRatio);
			int b = (int)(((float)baseColor.B) * colorRatio);
	

			Color c = Color.FromArgb(a, r, g, b);
			//Color c = MainVertexColor;
			//Color c = Color.FromArgb(a, r, g, b);
			return c;
			//return Color.SlateBlue;
			//get
			//{
			//    //Color sb = Color.SlateBlue;
			//    int zRatio = (int)(255 * Position.Z / MaxZForGradient);
			//    return Color.FromArgb(255, 0,0, zRatio);
			//}
		}

        /// <summary>
        /// Add some cool waves for stackintg effects that are starting in the same position
        /// </summary>

		protected List<List<EquilibriumPoint>> idxStrips = null;
		/// <summary>
		/// Create the index and vertex data together so we dont split up the functions.
		/// </summary>
		private void CreateIndexAndVertexData()
		{
			GC.Collect();
			
			//requires displacementField[xidx,yidx,zidx]
			//int stripVertices = 0;
			int zidx = 0;//zCount - 1;					//use last set of z points for surface... could also use an index in the middle or on bottom.

			idxStrips = new List<List<EquilibriumPoint>>();
			List<SVector> aData = new List<SVector>();

			int x_count = mParticles.GetUpperBound(0) + 1;
			int y_count = mParticles.GetUpperBound(1) + 1;  
			for (int xidx = 0; xidx < x_count; xidx++)
			{
				List<EquilibriumPoint> strip = new List<EquilibriumPoint>();

				for (int yidx = 0; yidx < y_count; yidx++)
				{
					Color c = GetColorForWater();//GetColorFromZ_LighterTop(mParticles[xidx, yidx, zidx]);
					SVector tempVector = mParticles[xidx, yidx, zidx].GetSVector();
					tempVector.SetColor(c);
					aData.Add(tempVector);


					if (xidx < x_count - 1)
					{
						if (yidx == 0)
						{
							EquilibriumPoint p1 = mParticles[xidx, yidx, zidx];
							strip.Add(p1);

							EquilibriumPoint p2 = mParticles[xidx + 1, yidx, zidx];
							strip.Add(p2);
							EquilibriumPoint p3 = mParticles[xidx + 1, yidx + 1, zidx];
							strip.Add(p3);
							//aData.Add(p2.GetSVector());

							//aData.Add(p3.GetSVector());
						}
						else if (yidx < y_count - 1)
						{
							EquilibriumPoint pEtc1 = mParticles[xidx, yidx, zidx];
							strip.Add(pEtc1);
							//aData.Add(pEtc1.GetSVector());
							EquilibriumPoint pEtc2 = mParticles[xidx + 1, yidx + 1, zidx];
							strip.Add(pEtc2);
							//aData.Add(pEtc2.GetSVector());
						}

					}
				}
				idxStrips.Add(strip);				
			}

			int idxCount = 0;
			foreach (List<EquilibriumPoint> strip in idxStrips)
			{
				int stripLength = strip.Count;
				idxCount += stripLength;
			}
			mSurfaceIndices = new int[idxCount];

			int surIdx = 0;
			int stripIdx = 0;
			foreach (List<EquilibriumPoint> strip in idxStrips)
			{
				foreach (EquilibriumPoint p in strip)
				{
					mSurfaceIndices[surIdx] = p.Index;
					surIdx++;
				}
				stripIdx++;
			}

			mVertexData = aData.ToArray();

		}

		public void Recreate()
        {

			GetDisplacementField();
			CreateIndexAndVertexData();
			//if (mEnableCallRenderIndexedPrimitives)
			//    RecreateIndexData();

			VertexBufferChanged(this, mVertexData.Length); //as soon as its registered calls will probably start arriving.
			//if (mEnableCallRenderIndexedPrimitives)
			IndexBufferChanged(this, mSurfaceIndices.Length); //as soon as its registered calls will probably start arriving.
		}

        ~FluidOld()
		{
			if (renderer != null)
				renderer.UnregisterPrimitive(this); //cannot hurt to unregister.
		}


        public void Register()
        {
            renderer.RegisterPrimitive(this); 
			mRegistered = true;
        }

        public void PreRender()
	    {
			if (GlobalTimerEnabled)
			{
				if (renderCounts %  framesPerRender == 0 && mTime != 0)
				{
					Recreate();
				}
				Time += dTime;
				renderCounts++;	
				if (renderCounts % 5 == 0 && Time != 0)
				{
					//RemoveDistantWaves();
					//AddWaves();
					//mLateralWaves.Add(RandomLateralWave0());
					renderCounts = 0; //reset
				}
			}
        }

		public void ResetAnimated()
		{
			Time = 0;
			renderCounts = 0;

			InitializeParticles();
			RemoveAllWaves();
			//AddRandomWavesSameWay();
		}
        public void RenderPrimitives(ManagedRenderer renderer, int yourDataLength)
        {
            //draw just the vertex data as points
            mDevice.DrawPrimitives(PrimitiveType.PointList, 0, mVertexData.Length);            
        }

		public void RenderIndexedPrimitives(ManagedRenderer caller, int vbDataLength, int ibLength)
		{
			//int expectedPrimitiveCount = ibLength / 3;
			//int primDifferenceWasted = expectedPrimitiveCount - PrimitiveCount;

			//try both
			//mDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vbDataLength, 0, PrimitiveCount);
			//mDevice.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, vbDataLength, 0, PrimitiveCount);
			int stripIdx = 0;
			foreach (List<EquilibriumPoint> strip in idxStrips)
			{
				if (strip.Count >= 3)
					mDevice.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, strip.Count, stripIdx * strip.Count, strip.Count - 2);
				stripIdx++;
			}
		}

        public void InitializeMaterial()
        {
			mMaterial = new Material();
			mMaterial.Specular = Color.FromArgb(122,255,255,255);
            mMaterial.Ambient = Color.FromArgb(122,255,255,255);
            mMaterial.Diffuse = Color.FromArgb(122,255,255,255);
        }

        [PGBrowsableAttribute]
        public Material Material
        {
			get { return mMaterial; }
			set { mMaterial = value; }
        }

        [PGBrowsableAttribute]
        public Vector3 Position
        {
            get { return position; }
            set { position = value;
				//dont forget to move buoy
				desiredBuoyPos = new Vector2(value.X, value.Y);
			}
        }

        public void ManagerDestroyed(ManagedRenderer caller)
        {
            //signals to registered primitive generator that renderer is or has been destroyed
            //so we should stop sending messages or at least relaying them to the renderer
            renderer = null;
        }

        public object GetVertices()
        {
		    return (object)mVertexData; //was SVector[]
        }
		public object GetIndices() //was int[]
		{
			return (object)mSurfaceIndices;
		}
		public int GetIndicesCount()
		{
			return mSurfaceIndices.Length;			
		}
        public int GetVerticesLength()
        {
            if (mVertexData == null)
                return 0;
            else
                return mVertexData.Length;
        }

        [PGBrowsableAttribute]
		public Color MainVertexColor
		{
			get { return mVertexColor; }
			set
			{
				mVertexColor = value;
				Recreate();
			}
		}

		public VertexFormats VertexFormat
		{
			get { return SVector.Format; }
		}

		protected float xMin = -100;
        [PGBrowsableAttribute]
		public float XMin
		{
			get { return xMin; }
			set { xMin = value;
			if (!this.GlobalTimerEnabled)
				Recreate();
			}
		}
		protected float xMax = 100;
        [PGBrowsableAttribute]
		public float XMax
		{
			get { return xMax; }
			set { xMax = value;
			if (!this.GlobalTimerEnabled)
				Recreate();
			}
		}
		protected int xCount = 10;
        [PGBrowsableAttribute]
		public int XCount
		{
			get { return xCount; }
			set { xCount = value;
			if (!this.GlobalTimerEnabled)
				Recreate();
			}
		}
		protected float yMin = -100;
        [PGBrowsableAttribute]
		public float YMin
		{
			get { return yMin; }
			set { yMin = value;
			if (!this.GlobalTimerEnabled)
				Recreate();
			}
		}
		protected float yMax = 100;
        [PGBrowsableAttribute]
		public float YMax
		{
			get { return yMax; }
			set { yMax = value;
			if (!this.GlobalTimerEnabled)
				Recreate();
			}
		}
		protected int yCount = 30;
        [PGBrowsableAttribute]
		public int YCount
		{
			get { return yCount; }
			set { yCount = value;
			if (!this.GlobalTimerEnabled)
				Recreate();
			}
		}
		protected float zMin = 1;
        [PGBrowsableAttribute]
		public float ZMin
		{
			get { return zMin; }
			set { zMin = value;
			if (!this.GlobalTimerEnabled)
				Recreate();
			}
		}
		protected float zMax = 30;
        [PGBrowsableAttribute]
		public float ZMax
		{
			get { return zMax; }
			set { zMax = value;
			if (!this.GlobalTimerEnabled)
				Recreate();
			}
		}
		protected int zCount = 1;
		protected int ZCount //NOT USED ANY MORE WE ONLY USE ONE LAYER FOR THE SURFACE.
		{
			get { return zCount; }
			//set
			//{
				//zCount = value;
				//if (!this.GlobalTimerEnabled)
				//	Recreate();
			//}
		}
        
		public void PostRender()
		{

		}
		protected bool mDoPreRender = true;
        [PGBrowsableAttribute]
		public bool PreRenderEnabled
		{
			get { return mDoPreRender; }
			set { mDoPreRender = value; }
		}
		protected bool mDoPostRender = false;
        [PGBrowsableAttribute]
		public bool PostRenderEnabled
		{
			get { return mDoPostRender; }
			set { mDoPostRender = value; }
		}
		protected bool mEnableCallRenderPrimitives = false;
        [PGBrowsableAttribute]
		public bool EnableCallRenderPrimitives
		{
			get { return mEnableCallRenderPrimitives; }
			set { mEnableCallRenderPrimitives = value; }
		}
		protected bool mEnableCallRenderIndexedPrimitives = true;
        [PGBrowsableAttribute]
		public bool EnableCallRenderIndexedPrimitives
		{
			get { return mEnableCallRenderIndexedPrimitives; }
			set { mEnableCallRenderIndexedPrimitives = value; }
		}

		protected bool mGlobalTimerEnabled = false;

		public bool GlobalTimerEnabled
		{
			get { return mGlobalTimerEnabled; }
			set { 
				if (value != mGlobalTimerEnabled)
				{
					mGlobalTimerEnabled = value;
					chkGlobalTimerEnabled.Checked = value;
				}
			}
		}

		
		
		private void lbLateralWaves_SelectedIndexChanged(object sender, EventArgs e)
        {

			pgSelectedWaves.SelectedObjects = SelectedWaves();//lbLateralWaves.SelectedItems.OfType<object>().Select<.ToArray<object>();
        }
		private object[] SelectedWaves()
		{
			List<object> waveList = new List<object>();
			foreach(object o in lbLateralWaves.SelectedItems.OfType<object>())
			{
				waveList.Add((object)(IEquilibriumWave3d)((ObjectListItem)o).ObjectAssociated);
			}
			return waveList.ToArray<object>();
		}

        private void btnAddWave_RandomNew_Click(object sender, EventArgs e)
        {
			DoAddWave(false, 0,0);
        }

		private void DoAddWave(bool useCoordinates, float centerPositionX, float centerPositionY)
		{
			lbLateralWaves.DataSource = null;

			int maxWaveCount;
			if (useCoordinates)
				maxWaveCount = 1;
			else
				maxWaveCount = (int)nudCount.Value;

			for (int waveCount = 0; waveCount < maxWaveCount; waveCount++)
			{
				IEquilibriumWave3d w = new EquilibriumWave3d();
				if (!useCoordinates)
				{
					float cpx = (float)rnddec(nudXMin.Value, nudXMax.Value);
					float cpy = (float)rnddec(nudYMin.Value, nudYMax.Value);
					float cpz = (float)rnddec(nudZMin.Value, nudZMax.Value);

					Vector2 CP = new Vector2(cpx, cpy);
					//float vx = (float)rnddec(nudVXMin.Value, nudVXMax.Value);
					//float vy = (float)rnddec(nudVYMin.Value, nudVYMax.Value);
					//float vz = (float)rnddec(nudVZMin.Value, nudVZMax.Value);
					//Vector3 V = new Vector3(vx, vy, vz);

					w.CenterPosition = CP;
					w.MaxLifeTime = (float)rnddec(nudLifeTimeMin.Value, nudLifeTimeMax.Value);
					w.Cz = (float)rnddec(nudAmplitudeMin.Value, nudAmplitudeMax.Value);
					w.TimerEnabled = chkLocalTimerEnabled.Checked;

				}
				else
				{
					w.Cz = .5f;
					w.CenterPosition = new Vector2(centerPositionX, centerPositionX);
					w.MaxLifeTime = 10; //for exerimentation only at this point
					w.TimerEnabled = true;

				}
				//w.V = V;				
				w.T0 = (float)Time;
				w.Frequency = (float)rnddec( nudFrequencyMin.Value, nudFrequencyMax.Value);

				//set wave type based on control checked values
				if (rbWaveTypeCos.Checked)
					w.WaveType = EquilibriumWave3d.WaveEquationType.Cos;
				else if (rbWaveTypeNormalCurve.Checked)
					w.WaveType = EquilibriumWave3d.WaveEquationType.NormalCurve;
				else if (rbWaveTypeSawTooth.Checked)
					w.WaveType = EquilibriumWave3d.WaveEquationType.SawTooth;
				else if (rbWaveTypeSin.Checked)
					w.WaveType = EquilibriumWave3d.WaveEquationType.Sin;
				else if (rbWaveTypeSquare.Checked)
					w.WaveType = EquilibriumWave3d.WaveEquationType.Square;
				else if (rbWaveTypeWater.Checked)
					w.WaveType = EquilibriumWave3d.WaveEquationType.WaterEffect;

			
				w.FixedWaveCount = (float)nudFixedWaveCount.Value;

				w.Rho0 = (float)rnddec(nudR0Min.Value, nudR0Max.Value);
				w.RhoSpeed = (float)rnddec(nudRadialSpeedMin.Value, nudRadialSpeedMax.Value);
				w.LengthOfEffect = (float)rnddec(nudLengthOfEffectMin.Value, nudLengthOfEffectMax.Value);
				w.NormalVariance = (float)rnddec(nudNormalVarianceMin.Value, nudNormalVarianceMax.Value);
				w.OutOfBoundsZero =chkSetOutOfBoundsToZero.Checked;
				w.Frequency = (float)rnddec(nudFrequencyMin.Value, nudFrequencyMax.Value);

				ObjectListItem listItem = new ObjectListItem(w, w.WaveNumber);
				listItem.ShortName = w.Name;
				mWaves.Add(w);
				mWaveListItems.Add(listItem);
				//lbLateralWaves.Focus();

				lbLateralWaves.Select();
			}

			lbLateralWaves.DataSource = mWaveListItems;
			lbLateralWaves.DisplayMember = "UniqueName";
			lbLateralWaves.ValueMember = "ObjectAssociated";
			lbLateralWaves.Update();

			Debug.WriteLine("t: " + Time.ToString() + ", wcount:" + mWaves.Count.ToString());

			Recreate();
		}

        private void btnRemoveSelectedWaves_Click(object sender, EventArgs e)
        {
            List<object> itemsToRemove = lbLateralWaves.SelectedItems.OfType<object>().ToList<object>();

            lbLateralWaves.DataSource = null;
            foreach (object o in itemsToRemove)
            {
                //change lbLateralWaves.DataSource			
				ObjectListItem listItem = ((ObjectListItem)o);
				mWaves.Remove((EquilibriumWave3d)listItem.ObjectAssociated);
				WaveListItems.Remove(listItem);
            }
			lbLateralWaves.DataSource = WaveListItems;
            lbLateralWaves.Update();
			Recreate();
        }

		private void rbWaveTypeNormalCurve_CheckedChanged(object sender, EventArgs e)
		{
			nudNormalVarianceMin.Enabled = rbWaveTypeNormalCurve.Checked;
		}

		private void FluidOld_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (e.CloseReason == CloseReason.UserClosing)
				e.Cancel = true;
			this.Hide();
		}

		private void chkGlobalTimerEnabled_CheckedChanged(object sender, EventArgs e)
		{
			this.GlobalTimerEnabled = chkGlobalTimerEnabled.Checked;
		}

		private void nudGlobalTime_ValueChanged(object sender, EventArgs e)
		{
			if (!initializing)
			{
				this.Time = (double)nudGlobalTime.Value;
			}
		}

		private void btnEnableAllTimers_Click(object sender, EventArgs e)
		{
			SetEnabledForAll(true);
			this.WindowState = FormWindowState.Minimized;
			btnEnableAllTimers.ForeColor = Color.Black;
			btnDisableAllTimers.ForeColor = Color.Green;
		}
		private void SetEnabledForAll(bool enabled)
		{
			foreach (object o in lbLateralWaves.Items)
			{
				IEquilibriumWave3d w = (IEquilibriumWave3d)((ObjectListItem)o).ObjectAssociated;
				w.TimerEnabled = enabled;
			}
			//last but not least enable the global timer
			this.GlobalTimerEnabled = enabled;
		}

		private void btnDisableAllTimers_Click(object sender, EventArgs e)
		{
			SetEnabledForAll(false);
			btnEnableAllTimers.ForeColor = Color.Green;
			btnDisableAllTimers.ForeColor = Color.Black;

		}

		private void rbWaveTypeWater_Click(object sender, EventArgs e)
		{
			SetOptions(EquilibriumWave3d.WaveEquationType.WaterEffect, sender);
		}
		private RadioButton oldColored = null;
		private void SetOptions(EquilibriumWave3d.WaveEquationType newWaveType, object sender)
		{
			if (oldColored != null)
				oldColored.ForeColor = Color.Black;

			((RadioButton)sender).ForeColor = Color.Crimson;
			oldColored = (RadioButton)sender;
			switch (newWaveType)
			{
				case EquilibriumWave3d.WaveEquationType.WaterEffect:
					nudAmplitudeMax.Value = 2;
					nudAmplitudeMin.Value = (decimal).25;
					break;
				case EquilibriumWave3d.WaveEquationType.Sin://fall through
				case EquilibriumWave3d.WaveEquationType.Cos:
					nudAmplitudeMin.Value = (decimal).1;
					nudAmplitudeMax.Value = 1;

					Vector3 CameraTarget = Camera.DefaultCamera.CameraTarget; 
					nudXMax.Value = (decimal)CameraTarget.X; //set before nud-Min
					nudXMin.Value = nudXMax.Value; //set after nud-MAx
					nudYMax.Value = (decimal)CameraTarget.Y; //set before nud-Min
					nudYMin.Value = nudYMax.Value; //set after nud-MAx
					nudZMax.Value = (decimal)CameraTarget.Z; //set before nud-Min
					nudZMin.Value = nudZMax.Value; //set after nud-MAx
					break;
				case EquilibriumWave3d.WaveEquationType.NormalCurve:
					float radialLength = 100;
					nudAmplitudeMax.Value = 5;		//hey even 5 foot waves are good
					nudAmplitudeMin.Value = 50;		//wow a fifty-foot wave
					nudR0Min.Value = 100;
					nudXMax.Value = (decimal)(xMax - radialLength);
					nudXMin.Value = (decimal)(xMin - radialLength);
					break;
			}
		}
		private void rbWaveTypeSin_Click(object sender, EventArgs e)
		{
			SetOptions(EquilibriumWave3d.WaveEquationType.Sin, sender);
		}

		private void rbWaveTypeCos_Click(object sender, EventArgs e)
		{
			SetOptions(EquilibriumWave3d.WaveEquationType.Cos, sender);
		}



		private void rbWaveTypeSquare_Click(object sender, EventArgs e)
		{
			SetOptions(EquilibriumWave3d.WaveEquationType.Square, sender);
		}

		private void rbWaveTypeSawTooth_Click(object sender, EventArgs e)
		{
			SetOptions(EquilibriumWave3d.WaveEquationType.SawTooth, sender);

		}

		private void rbWaveTypeNormalCurve_Click(object sender, EventArgs e)
		{
			SetOptions(EquilibriumWave3d.WaveEquationType.NormalCurve, sender);
		}

		private void pgSelfViewer_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
		{
			Recreate();
		}

		private void pgSelectedWaves_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
		{
			Recreate();
		}

		private void chkChangeCamera_Click(object sender, EventArgs e)
		{
			onlyBuoy.AllowChangeCamera = chkChangeCamera.Checked;
		}


    }

}

